#include <jni.h>
#include <string>
#include <android/log.h>
#include "3des.h"
#include <iostream>
#define LOGE(FORMAT,...) __android_log_print(ANDROID_LOG_ERROR,"david",FORMAT,##__VA_ARGS__);

using namespace std;
extern "C"
JNIEXPORT jstring JNICALL
Java_com_ewhome_apartment_mvp_ui_activity_UserActivity_stringFromJNI(JNIEnv *env, jobject ) {
    string hello = "EEF5B20853C08E686A262FC28C26E875";
    string a=GY_Decrypt(hello);
    LOGE("a= %s\n",a.data())
    return env->NewStringUTF(a.data());
}extern "C"
JNIEXPORT jstring JNICALL
Java_com_ewhome_apartment_app_GlobalHttpHandlerImpl_encodeFromJNI(JNIEnv *env, jobject instance,
                                                                  jstring orgin_) {
    const char *orgin = env->GetStringUTFChars(orgin_, 0);

    // TODO
    env->ReleaseStringUTFChars(orgin_, orgin);
    string a=GY_Encrypt(orgin);
    LOGE("a= %s\n",a.data())
    return env->NewStringUTF(a.data());
}extern "C"
JNIEXPORT jstring JNICALL
Java_com_ewhome_apartment_app_GlobalHttpHandlerImpl_decodeFromJNI(JNIEnv *env, jobject instance,
                                                                  jstring des_) {
    const char *str;
    str = env->GetStringUTFChars(des_, false);
    if(str == NULL) {
        return NULL;
    }
    env->ReleaseStringUTFChars(des_, str);
    LOGE("ssss= %s\n",str)
    char mstr[strlen(str)];
    sprintf(mstr,"%s" , str);
    string a=GY_Decrypt(mstr);

    return env->NewStringUTF(a.data());;
}
extern "C"
JNIEXPORT jstring JNICALL
Java_com_ewhome_apartment_mvp_presenter_UserPresenter_decodeFromJNI(JNIEnv *env, jobject instance,
                                                                    jstring str_) {
    const char *str = env->GetStringUTFChars(str_, 0);

    // TODO
    LOGE("ssss= %s\n",str)

    env->ReleaseStringUTFChars(str_, str);

    string a=GY_Decrypt(str);
    LOGE("a= %s\n",a.data())
    return env->NewStringUTF(a.data());
}

